package com.example.demo.model;

import java.util.HashMap;

import org.springframework.http.HttpStatus;

/**
 * @author jiangwz
 * @create 2019/9/19.
 */
public class Result extends HashMap<String, Object> {


    public Result() {
        put("code", HttpStatus.OK.value());
        put("msg", "操作成功");
    }

    public static Result ok(){
        return new Result();
    }

    public static Result ok(String msg){
        Result result = new Result();
        result.put("msg", msg);
        return result;
    }

    public static Result error(String message) {
        return error(message, HttpStatus.INTERNAL_SERVER_ERROR.value());
    }

    public static Result error(String message, int code) {
        Result result = new Result();
        result.put("code", code);
        result.put("msg", message);
        return result;
    }

    @Override
    public Object put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
